package com.igeek.d0612;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Author: zhiyu
 * @Date:16:47
 * @DESC:
 */
public class Test3 {
    private static List<String> strings = new CopyOnWriteArrayList<>();
    public static void main(String[] args) {
        newThread(randomTest());
        strings.forEach(System.out::println);
    }
    public static void newThread(int n){
        for (int i = 1; i <= n; i++) {
            Thread thread = new Thread(() -> {
                strings.add(Thread.currentThread().getName());
            }, "线程" + i);
            thread.start();
            try {
                thread.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
    public static int randomTest(){
        int n = (int) Math.floor(Math.random()*10);
        if (n==0){
            return randomTest();
        }else {
            return n;
        }
    }
}
